<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" th:href="@{/css/base.css}">
<link rel="stylesheet" type="text/css" th:href="@{/css/style.css}">
<title>资产地图</title>
<style type="text/css">
html,
body,
#container {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    padding: 0px;
    margin: 0px;
    background-color: #efefef;
}
ul,li{
    list-style: none;
}
</style>
<script th:inline="javascript">
var map = null;
var myValue;
$(function(){
	// 在指定容器创建地图实例并设置最大最小缩放级别
	map = new BMap.Map("container");
	
	//初始化地图，设置中心点和显示级别
	map.centerAndZoom(new BMap.Point(105.444933,28.890888), 12);
	
	//开启鼠标滚轮缩放功能，仅对PC上有效
	map.enableScrollWheelZoom(true);
	
	// 将控件（平移缩放控件）添加到地图上
	map.addControl(new BMap.NavigationControl());
	
	//单击获取点击的经纬度
	map.addEventListener("click",function(e){
		map.clearOverlays();    //清除地图上所有覆盖物
		$('#lng').val(e.point.lng);
		$('#lat').val(e.point.lat);
		//添加一个标注
		let point = new BMap.Point(e.point.lng, e.point.lat);
		var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(46, 50), {
		    offset: new BMap.Size(10, 25),
		    imageOffset: new BMap.Size(0, 0 - 12 * 25) // 设置图片偏移
		});
		var marker = new BMap.Marker(point,{icon: myIcon});
		map.addOverlay(marker);    //添加标注
	});
	
	//建立一个自动完成的对象
	var ac = new BMap.Autocomplete(
		{"input" : "suggestId"
		,"location" : map
	});
	ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
		var str = "";
		var _value = e.fromitem.value;
		var value = "";
		if (e.fromitem.index > -1) {
			value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
		}    
		str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
		
		value = "";
		if (e.toitem.index > -1) {
			_value = e.toitem.value;
			value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
		}    
		str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
		G("searchResultPanel").innerHTML = str;
	});
	
	ac.addEventListener("onconfirm", function(e) {//鼠标点击下拉列表后的事件
	var _value = e.item.value;
		myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
		G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
		
		setPlace();
	});
});
function setPlace(){
	map.clearOverlays();    //清除地图上所有覆盖物
	function myFun(){
		var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
		map.centerAndZoom(pp, 18);
		var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(46, 50), {
		    offset: new BMap.Size(10, 25),
		    imageOffset: new BMap.Size(0, 0 - 12 * 25) // 设置图片偏移
		});
		var marker = new BMap.Marker(pp,{icon: myIcon});
		map.addOverlay(marker);    //添加标注
        marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
        $('#lng').val(pp.lng);
		$('#lat').val(pp.lat);
	}
	var local = new BMap.LocalSearch(map, { //智能搜索
	  onSearchComplete: myFun
	});
	local.search(myValue);
}
function G(id) {
	return document.getElementById(id);
}
//确认坐标信息
function confirm(){
	try{
		window.opener.setCoordinate($('#lng').val(),$('#lat').val());
	}catch(e){};
	window.close();
}
</script>
</head>

<body>
	<div id="r-result">
		请输入要检索的地址:<input type="text" id="suggestId" size="20" value="" style="width:230px;" />
		<div style="float:right">
			<input type="text" id="lng" size="20" style="width:180px;" placeholder="经度"/>
			<input type="text" id="lat" size="20" style="width:180px;" placeholder="纬度"/>
			<button class="btn btn-minier btn-info" type="button" onclick="confirm()">
				<i class="ace-icon fa fa-check bigger-110"></i>
				<span class="bigger-110 no-text-shadow">确定</span>
			</button>
			<span style="color:red">在地图上点击选取坐标后点“确定”获取经纬度</span>
		</div>
	</div>
	<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
    <!-- 地图盒子 -->
    <div id="container"></div>
    <!-- 调用百度地图 -->
    <script type="text/javascript" src="http://api.map.baidu.com/api?ak=IKO5vxfEGfTVytD2VXlqmIXIwmVcBaeE&v=3.0"></script>
</body>

</html>